<div class="pageContent">
	<div class="tabsHeader panel collapse" style="width:100%; overflow:auto; float:left;background-color:#d8e5f1;" id="dhlLogFilter" defH="170" OnToggle="dhlPanelFun">
		<h1>历史日志查询参数</h1>
		<div>
			<fieldset style="width:205px; height:155px; float:left;" >
				<legend>应用模块过滤</legend>
				<div style="margin-left:5px;">
				<label>应用</label>
				<select id="dhl_appName" style="width:120px">
					<option value="-">-</option>
				</select>
				<span><input id='dhl_flt_all_am' type='checkbox' onclick="dhlSelectAllModule()">
					<label class="for" title="选择全部模块" for="dhl_flt_all_am">全选</label></span>
				</div>

				<fieldset style="margin-top:5px; height:105px; overflow:auto">
				<div id="dhl_flt_app_module"> </div>
				</fieldset>
			</fieldset>
			<fieldset style="width:75px; height:155px; float:left; margin-left:5px"> 
				<legend>日志类型</legend>
				<div>
					<input type="checkbox" value="2" name="dhlLogType" id="dhlLogType2" checked >
					<label class="for" title="调试日志" for="dhlLogType2">调试日志</label>
				</div>
				<div>
					<input type="checkbox" value="4" name="dhlLogType" id="dhlLogType4" checked >
					<label class="for" title="信息日志" for="dhlLogType4">信息日志</label>
				</div>
				<div>
					<input type="checkbox" value="8" name="dhlLogType" id="dhlLogType8" checked >
					<label class="for" title="警告日志" for="dhlLogType8">警告日志</label>
				</div>
				<div>
					<input type="checkbox" value="16" name="dhlLogType" id="dhlLogType16" checked >
					<label class="for" title="输入错误日志" for="dhlLogType16">输入错误</label>
				</div>
				<div>
					<input type="checkbox" value="32" name="dhlLogType" id="dhlLogType32" checked >
					<label class="for" title="程序错误日志" for="dhlLogType32">程序错误</label>
				</div>
				<div>
					<input type="checkbox" value="64" name="dhlLogType" id="dhlLogType64" checked >
					<label class="for" title="严重错误日志" for="dhlLogType64">严重错误</label>
				</div>
				<div>
					<input type="checkbox" value="1" name="dhlLogType" id="dhlLogType1" checked >
					<label class="for" title="其它类型" for="dhlLogType1">其它类型</label>
				</div>
			</fieldset>

			<fieldset style="width:170px; height:155px; float:left; margin-left:5px;"> 
				<legend>日志展示字段</legend>
				<table>
					<tr>
						<td><input name="dhl_log_field" id="dhl_log_field_logtype" type="checkbox" title="日志类型"checked value="512">
						<label class="for" title="日志类型" for="dhl_log_field_logtype">日志类型</label>
						</td>
						<td><input name="dhl_log_field" id="dhl_log_field_cust1" type="checkbox" title="应用模块自定义字段-1" value="4">
						<label class="for" title="应用模块自定义字段-1" for="dhl_log_field_cust1">自定义字段1</label>
						</td>
					</tr>
					<tr>
						<td><input name="dhl_log_field" id="dhl_log_field_time" type="checkbox" title="该条日志的产生时间"checked value="1">
						<label class="for" title="该条日志的产生时间" for="dhl_log_field_time">日志时间</label>
						</td>
						<td><input name="dhl_log_field" id="dhl_log_field_cust2" type="checkbox" title="应用模块自定义字段-2" value="32">
						<label class="for" title="应用模块自定义字段-2" for="dhl_log_field_cust2">自定义字段2</label>
						</td>
					</tr>
					<tr> 
						<td><input name="dhl_log_field" id="dhl_log_field_pos" type="checkbox" title="产生该条日志的文件位置"checked value="2048">
						<label class="for" title="产生该条日志的文件位置" for="dhl_log_field_pos">日志位置</label>
						</td>
						<td><input name="dhl_log_field" id="dhl_log_field_cust3" type="checkbox" title="应用模块自定义字段-3" value="256">
						<label class="for" title="应用模块自定义字段-3" for="dhl_log_field_cust3">自定义字段3</label>
						</td>
					</tr>
					<tr>
						<td><input name="dhl_log_field" id="dhl_log_field_app" type="checkbox" title="该条日志所属应用" value="8">
						<label class="for" title="该条日志所属应用" for="dhl_log_field_app">所属应用</label>
						</td>
						<td><input name="dhl_log_field" id="dhl_log_field_cust4" type="checkbox" title="应用模块自定义字段-4" value="1024">
						<label class="for" title="应用模块自定义字段-4" for="dhl_log_field_cust4">自定义字段4</label>
						</td>
					</tr>
					<tr>
						<td><input name="dhl_log_field" id="dhl_log_field_module" type="checkbox" title="该条日志所属模块"checked value="16">
						<label class="for" title="该条日志所属模块" for="dhl_log_field_module">所属模块</label>
						</td>

						<td><input name="dhl_log_field" id="dhl_log_field_cust5" type="checkbox" title="应用模块自定义字段54" value="4096">
						<label class="for" title="应用模块自定义字段-5" for="dhl_log_field_cust5">自定义字段5</label>
						</td>
					</tr>
					<tr>
						<td><input name="dhl_log_field" id="dhl_log_field_logconfig" type="checkbox" title="该条日志的日志配置" value="128"> 
						<label class="for" title="该条日志的日志配置" for="dhl_log_field_logconfig">日志配置</label>
						</td>
						<td><input name="dhl_log_field" id="dhl_log_field_cust6" type="checkbox" title="应用模块自定义字段64" value="8192">
						<label class="for" title="应用模块自定义字段-6" for="dhl_log_field_cust6">自定义字段6</label>
						</td>
					</tr>
					<tr>
						<td><input name="dhl_log_field" id="dhl_log_field_content" type="checkbox" title="日志内容"checked value="64">
						<label class="for" title="日志内容" for="dhl_log_field_content">日志内容</label>
						</td>
						<td><input name="dhl_log_field" id="dhl_log_field_addr" type="checkbox" title="产生该条日志的机器地址"checked value="2">
						<label class="for" title="产生该条日志的机器地址" for="dhl_log_field_addr">日志上报机器</label>
						</td>
					</tr>
				</table>
			</fieldset>

			<fieldset style="width:240px; height:100px; float:left; margin-left:5px;" >
				<legend>包含关键字【与】</legend>
				<input style='padding:0' id="dhl_key_include" size="16" type="text" title="日志包含关键字，多个包含关键字之间的关系为与关系" value="" maxlength="16" onkeyup="this.value=this.value.replace(/[_]/g,'')" onafterpaste="this.value=this.value.replace(/[_]/g,'')" >
				<span>
					<button onclick="dhlAddLogKey(true, 'dhl_inc_keylist');"><i class='icon-plus'></i>添加</button>
				</span>
				<span>
					<button onclick="dhlClearLogKey('dhl_inc_keylist', 'dhl_key_include');"><i class='icon-trash'></i>清空</button>
				</span>

				<fieldset style="margin-top:5px; height:45px; overflow:auto">
					<div id="dhl_inc_keylist"> </div>
				</fieldset>
			</fieldset>

			<fieldset style="width:240px; height:100px; float:left; margin-left:5px;" >
				<legend>排除关键字【或】</legend>
				<input id="dhl_key_exce" size="16" style='padding:0' type="text" title="日志排除关键字，多个排除关键字之间的关系为或关系" value="" maxlength="10">
				<span>
					<button onclick="dhlAddLogKey(false, 'dhl_exce_keylist');"><i class='icon-plus'></i>添加</button>
				</span>
				<span>
					<button onclick="dhlClearLogKey('dhl_exce_keylist', 'dhl_key_exce');"><i class='icon-trash'></i>清空</button>
				</span>
				<fieldset style="margin-top:5px; height:45px; overflow:auto">
					<div id="dhl_exce_keylist"> </div>
				</fieldset>
			</fieldset>

			<fieldset style="width:160px; height:42px; float:left; margin-left:5px;" >
				<legend>上报机器</legend>
				<div>
					<select id="dhlReportHost" title="按上报机器过滤日志">
						<option value="0">全部机器</option>
					</select>
				</div>
			</fieldset>

			<fieldset style="width:120px; height:42px; float:left; margin-left:5px;"> 
				<legend>接收记录数</legend>
				<div>
					<label>最多接收</label>
					<select id="dhlMaxRecords">
						<option value="50">50</option>
						<option value="100" selected>100</option>
						<option value="300">300</option>
						<option value="500">500</option>
						<option value="1000">1000</option>
						<option value="2000">2000</option>
					</select>
				</div>
			</fieldset>

			<fieldset style="width:534px; height:42px; float:left; margin-left:5px; display:none" id="dhlCustTime"> 
				<legend>自定义时间段</legend>
				<div>
					<label>开始</label>
					<input type="text" id="dhlLogTimeStart" style='padding:0' class="date" value="" dateFmt="yyyy-MM-dd HH:mm:ss" readonly="true"/>
					<label>结束</label>
					<input type="text" id="dhlLogTimeEnd" class="date" style='padding:0' value="" dateFmt="yyyy-MM-dd HH:mm:ss" readonly="true"/>
					&nbsp;&nbsp;
					<button onclick="$('#dhlCustTime').css('display', 'none'); $('#dhlCommTime').css('display', 'block');"><i class='icon-time'></i>常用时间段</button>
					&nbsp;
					<button onclick="$('#dhlCustTime').css('display', 'none'); $('#dhlCustLog').css('display', 'block');"><i class='icon-clone'></i>指定文件</button>
				</div>
			</fieldset>
			<fieldset style="width:294px; height:42px; float:left; margin-left:5px;" id="dhlCommTime"> 
				<legend>常用时间段</legend>
				<div>
					<label>最近</label>
					<select id="dhlLogLastTime">
						<option value="300">5 分钟</option>
						<option value="1800" selected>30 分钟</option>
						<option value="3600">1 小时</option>
						<option value="43200">12 小时</option>
						<option value="86400">1 天</option>
						<option value="604800">7 天</option>
						<option value="2592000">30 天</option>
						<option value="31536000">1 年</option>
						<option value="315360000">10 年</option>
						<option value="630720000">20 年</option>
					</select>
					<button onclick="$('#dhlCommTime').css('display', 'none'); $('#dhlCustTime').css('display', 'block');"><i class='icon-time'></i>自定义时间段</button>
					<button onclick="$('#dhlCommTime').css('display', 'none'); $('#dhlCustLog').css('display', 'block');"><i class='icon-clone'></i>指定文件</button>
				</div>
			</fieldset>
			<fieldset style="width:334px; height:42px; float:left; margin-left:5px; display:none" id="dhlCustLog"> 
				<legend>指定日志文件</legend>
				<div>
					<select id="dhlLogFile" style="width:160px;text-align:center">
						<option value="0" selected>--- 请选择 ---</option>
					</select>
					<button onclick="$('#dhlCustLog').css('display', 'none'); $('#dhlCustTime').css('display', 'block');"><i class='icon-time'></i>自定义时间</button>
					<button onclick="$('#dhlCustLog').css('display', 'none'); $('#dhlCommTime').css('display', 'block');"><i class='icon-time'></i>常用时间</button>
				</div>
			</fieldset>

		</div>
	</div>

	<div class="formBar"> 
		<div style="float:left; width:260px; margin-top:5px;">
			<h1 id="dhl_History_status_recv">历史日志</h1>
		</div>
		<div style="float:left; margin-top:5px;">
			[ 第<span id="dhlFileNo" class="log_status_info">0</span>/
			<span id="dhlFileCount" class="log_status_info">0</span>个文件，当前文件已扫描
			<span id="dhlPercentage" class="log_status_info">0</span>%，
			已扫描记录：<span id="dhlTotalRecords">0</span> ]
		</div>
		<ul>
	        <li><button class="buttonActive" type="button" onclick="dhlShowHistory();" id="dhl_button_search"><i class='icon-search icon-large'></i>查找</button></li>
	        <li><button class="buttonActive" type="button" onclick="dhlChangeSortByTime();" id="dhl_button_sort"><i class='icon-time icon-large'></i>变换时间顺序</button></li>
	        <li><button class="buttonActive" type="button" onclick="dhlClearHistoryLog();"><i class='icon-trash icon-large'></i>清 空</button></li>
	        <li><button class="buttonActive" type="button" onclick="dhlShowMax();" id='dhl_button_show'><i class="icon-move icon-large"></i>扩展显示区</button></li>
	    </ul>
	</div>

	<div class="unitBox"> 
		<ol id="dhlHistoryList" layoutH='0'></ol>
	</div> <!-- panel 历史日志 -->
</div>

<script language="javascript" type="text/javascript">

var dhl_app_module_list = $.parseJSON('<?cs var:config.app_module_list ?>');
var dhl_report_machines = $.parseJSON('<?cs var:config.report_machines ?>');
var dhl_logRequestNo = 0; // 用于请求响应配对
var dhl_logRecvTotal = 0;
var dhl_logLostTotal = 0;
var dhl_show_max = false;
var dhl_status_times = 0;
var dhl_interval_id = 0;
var dhl_time_id = 0;
var dhl_log_type_bg = [];
var dhl_log_type_nm = [];
var dhl_showlog_ary = ["[]", "{}", "()"];
var dhl_fileNo = 0;
var dhl_filePos = 0;
var dhl_fileCount = 0;
var dhl_fileIndexStar = 0;
var dhl_showPageRecords = 0;
var dhl_recvTotalRecords = 0;
var dhl_result_list_save = [];
var dhl_result_list_sort_up = true;
var dhl_query_app_id = <?cs alt:config.qu_app_id ?>0<?cs /alt ?>;
var dhl_query_log_file = '<?cs var:config.qu_log_file ?>';

function dhlGetModuleNameById(id)
{
	if(dhl_app_module_list == null || dhl_app_module_list.app_count <= 0) 
		return "未知模块";

	var app_list = dhl_app_module_list.applist;
	for (var i = 0; i < app_list.length; ++i) { 
		for(var j=0; j < app_list[i].module_count; j++)
			if(app_list[i].modulelist[j].id == id)
				return app_list[i].modulelist[j].name;
	}
	return "未知模块";
}


function dhlGetAppNameById(id)
{
	if(dhl_app_module_list == null || dhl_app_module_list.app_count <= 0) 
		return "未知应用";

	var app_list = dhl_app_module_list.applist;
	for (var i = 0; i < app_list.length; ++i) { 
		if(app_list[i].app_id == id)
			return app_list[i].app_name;
	}
	return "未知应用";
}

function dhlPanelFun(c)
{
	var hfilter = parseInt($("#dhlLogFilter").attr("defH"));
	var hshow = parseInt($("#dhlHistoryList").height());
	var hshow_dapt = 8;
	if(c == 1) 
		$("#dhlHistoryList").height(hshow+hfilter+hshow_dapt);
	else 
		$("#dhlHistoryList").height(hshow-hfilter-hshow_dapt);

}

function dhlShowMax()
{
	var hfilter = parseInt($("#dhlLogFilter").attr("defH"));
	var hfcont = $("#dhlLogFilter").height();
	var hshow = parseInt($("#dhlHistoryList").height());

	// 查询参数设置区内容隐藏/显示的情况区分处理
	var hshow_dapt = 33;
	if(hfcont > hshow_dapt)
		hshow_dapt += hfilter + 5;
	if(dhl_show_max){
		dhl_show_max = false;
		$("#dhl_button_show").text("扩展显示区");
		$("#dhlLogFilter").show(100);
		if(DWZ.ui.sbar == false)
		    $("#navTab .tabsPageHeader a.toggleCollapse").trigger("click");
		$("#dhlHistoryList").height(hshow-hshow_dapt);
	}
	else {
		dhl_show_max = true;
		$("#dhl_button_show").text("收缩显示区");
		$("#dhlLogFilter").hide(100);
		if(DWZ.ui.sbar == true)
		    $("#navTab .tabsPageHeader a.toggleCollapse").trigger("click");
		$("#dhlHistoryList").height(hshow+hshow_dapt);
	}
}

function dhlClearHistoryLog()
{
	dhl_result_list_save = [];
	$('#dhlHistoryList').html("");
}

function dhlGetShowLogChar(j, i)
{
	if(j >= dhl_showlog_ary.length)
		j = 0;
	return dhl_showlog_ary[j][i];
}

function dhlShowHistory()
{
	if(dhl_interval_id != 0) {
		clearTimeout(dhl_interval_id);
		dhl_interval_id = 0;
	}
	if(dhl_time_id != 0) {
		clearTimeout(dhl_time_id);
		dhl_time_id = 0;
	}

	if(!dhlShowHistoryLog())
		return false;
	var appIdx = $("#dhl_appName").val();
	window.localStorage.setItem('dhl_app_sel', dhl_app_module_list.applist[appIdx].app_id);

	dhl_interval_id = setTimeout("dhlShowHistoryStatus();", 300);
	dhl_time_id = setTimeout(function(){
			if(dhl_interval_id != 0) {
				clearTimeout(dhl_interval_id);
				dhl_interval_id = 0;
			}
			$("#dhl_History_status_recv").css('color', 'red').text("历史日志 【 查询超时】");
			dhl_logRequestNo++;
		}, 30000);
	$("#dhl_button_search").html("<i class='icon-search icon-large'></i>重新查找");
}

function dhlSelectAllModule()
{
	$("#dhl_flt_app_module input[name=dhl_flt_module]").each(function () {
		if($("#dhl_flt_all_am").is(":checked"))
			$(this).prop("checked", true);
		else
			$(this).prop("checked", false);
	});
	return true;
}

function dhlSortByTime(a, b)
{
    if (b.s_time && a.s_time) {
		if(a.s_time > b.s_time)
			return (dhl_result_list_sort_up ? 1 : -1);
		else if(a.s_time < b.s_time)
			return (dhl_result_list_sort_up ? -1 : 1);
		return 0;
    } else {
        return 0;
    }
}

function dhlSortShowHistoryLog()
{
	if(dhl_result_list_save.list.length <= 0)
		return 0;
	
	var result = dhl_result_list_save;
	result.list.sort(dhlSortByTime);
	var ct = $('#dhlHistoryList');
	var ctlist = "";
	var ctadd = "";
	var logtype = "";
	for(var i=0,j=0; i < result.list.length; i++){
		logtype = result.list[i].type.toString();
		if(typeof dhl_log_type_bg[logtype] != "undefined"){
			ctadd = '<li class="log_type_' + dhl_log_type_bg[logtype] + '">';
			if(result.LogField & 512){
				ctadd += "<span>"+dhlGetShowLogChar(j,0)+dhl_log_type_nm[logtype]
					+ dhlGetShowLogChar(j++, 1)+" </span>";
				if(j >= dhl_showlog_ary.length)
					j = 0;
			}
		}
		else {
			ctadd = '<li class="log_type_other">';
			if(result.LogField & 512) {
				ctadd += "<span>"
					+dhlGetShowLogChar(j,0)+"其它类型"+dhlGetShowLogChar(j++, 1)+" </span>";
				if(j >= dhl_showlog_ary.length)
					j = 0;
			}

		}
		if(result.LogField & 1) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].time + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 2048) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].pos + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 8) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + dhlGetAppNameById(result.list[i].app) + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 16) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + dhlGetModuleNameById(result.list[i].module) + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 128) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].config + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 4) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].cust_1 + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 32) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].cust_2 + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 256) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].cust_3 + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 1024) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].cust_4 + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 4096) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].cust_5 + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		if(result.LogField & 8192) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].cust_6 + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}


		if(result.LogField & 64) 
			ctadd += "<span class='log_content'> --- "+dmtEncodeHTML(result.list[i].Content)+" </span>";

		if(result.LogField & 2) {
			ctadd += "<span>"+dhlGetShowLogChar(j,0) + result.list[i].addr + dhlGetShowLogChar(j++, 1)+" </span>";
			if(j >= dhl_showlog_ary.length)
				j = 0;
		}

		ctadd += '</li>'; 
		ctlist = ctadd + ctlist;
	}
	ct[0].innerHTML = ctlist;

	// 高亮关键字
	$("#dhl_inc_keylist").children('.log-keyword').children('span').each(function () {
			ct.highlight($(this).text());
	});
}

function dhlShowHistoryLogResult(result)
{
	if(dhl_time_id != 0) 
	{
		clearTimeout(dhl_time_id);
		dhl_time_id = 0;
	}
	if(dmtFirstDealAjaxResponse(result))
	{
		return;
	}

	if (dhl_interval_id != 0) {
		clearTimeout(dhl_interval_id);
		dhl_interval_id = 0;
	}

	if(dhl_logRequestNo != result.RequestNo) {
		dhl_logRequestNo++;
		var msg = "历史日志 【 查询出错";
		if(typeof result.msg != "undefined")
			msg = msg + "：" + result.msg;
		$("#dhl_History_status_recv").css('color', 'red').text(msg);
		return;
	}

	dhl_logRequestNo++;

	if(result.ec == 888)
		$("#dhl_History_status_recv").css('color', 'black').text("历史日志 【 扫描完成 】");
	else if(result.ec != 0) {
		alertMsg.error("历史日志获取失败！");
		return;
	}
	else
		$("#dhl_History_status_recv").css('color', 'black').text("历史日志 【 扫描部分完成 】").attr("font-style", "red");

	dhl_fileCount = result.FileCount - 0;
	dhl_fileNo = result.FileNo;
	dhl_filePos = result.FilePos;
	dhl_fileIndexStar = result.FileIndexStar;
	if(typeof result.list != "undefined")
		dhl_recvTotalRecords += result.list.length - 0;

	$("#dhlPercentage").text(result.Percentage);
	$("#dhlFileCount").text(result.FileCount);
	$("#dhlFileNo").text(result.FileNo+1);
	$("#dhlTotalRecords").text(dhl_recvTotalRecords);

	if(dhl_fileCount < 1)
		dhl_fileNo = -1;

	if(typeof result.list != "undefined" && result.list.length > 0) {
		dhl_result_list_save = result;
		dhlSortShowHistoryLog();
   }
}

function dhlShowHistoryStatus()
{
	dhl_status_times++;
	var show = new Array((dhl_status_times%8)+1).join(".");
	$("#dhl_History_status_recv").css('color', 'black').text("历史日志 【 查询中 "+show);
	dhl_interval_id = setTimeout("dhlShowHistoryStatus();", 300);
}

function dhlShowHistoryLog()
{
	// 重置显示区和查询状态
	dhlClearHistoryLog();
	dhl_fileNo = 0;
	dhl_filePos = 0;
	dhl_fileCount = 0;
	dhl_fileIndexStar = 0;
	dhl_recvTotalRecords = 0;
	dhl_result_list_save = [];

	var para = new Object();

	// 应用模块 --
	var appIdx = $("#dhl_appName").val();
	para.appId = dhl_app_module_list.applist[appIdx].app_id;
	if(dhl_app_module_list.applist[appIdx].module_count <= 0){
		alertMsg.warn("所选应用，模块数目为0，请先添加模块！");
		return false;
	}
	para.moduleIdList = "";
	$("#dhl_flt_app_module input[name=dhl_flt_module]").each(function () {
			if (this.checked) {
				if(para.moduleIdList == "")
					para.moduleIdList = this.value;
				else
					para.moduleIdList += "_" + this.value;
			}
	});
	if(para.moduleIdList == "") {
		alertMsg.warn("请在 [应用模块过滤] 的模块列表中选择要显示日志的模块！");
		return false;
	}

	// 日志类型 --
	para.logType = 0;
	$("input[name=dhlLogType]").each(function(){
			if(this.checked)
				para.logType |= this.value;
	});
	if(para.logType == 0) {
		alertMsg.warn("请选择要显示的日志类型！");
		return false;
	}

	// 包含关键字 --
	var keylist = "";
	$("#dhl_inc_keylist").children('.log-keyword').children('span').each(function () {
			if(keylist == "")
				keylist = $(this).text();
			else
				keylist += "_" + $(this).text();
	});
	if(keylist != "")
		para.incKeyList = keylist;

	// 排除关键字 --
	keylist = "";
	$("#dhl_exce_keylist").children('.log-keyword').children('span').each(function () {
			if(keylist == "")
				keylist = $(this).text();
			else
				keylist += "_" + $(this).text();
	});
	if(keylist != "")
		para.exceKeyList = keylist;

	// 日志展示字段 ---
	para.logField = 0;
	$("input[name=dhl_log_field]").each(function(){
			if(this.checked)
				para.logField |= this.value;
	});
	if(para.logField == 0) {
		alertMsg.warn("请选择要显示的日志字段！");
		return false;
	}

	// 时间段 ---
	if($("#dhlCustTime").css("display") == "block") {
		var StartTime = dmtGetTimeStamp($("#dhlLogTimeStart").val());
		var StopTime = dmtGetTimeStamp($("#dhlLogTimeEnd").val());
		if(StartTime == "" || StopTime == ""){
			alertMsg.warn("请点击输入框选择时间段！");
			return false;
		}
		else if(StopTime <= StartTime) {
			alertMsg.warn("日志时间段，结束时间必须大于开始时间，请重新输入！");
			return false;
		}
		para.StartTime = StartTime;
		para.StopTime = StopTime;
	}
	else if($("#dhlCommTime").css("display") == "block") {
		para.LastTime = $("#dhlLogLastTime").val();
	}
	else {
		para.LogFile = $("#dhlLogFile").val();
		if(para.LogFile == '0'){
			alertMsg.warn("请选择日志文件！");
			return;
		}
	}

	// 上报机器
	para.machine = $('#dhlReportHost').val();
	
	// 接收的最大记录数 ---
	dhl_showPageRecords = $("#dhlMaxRecords").val();

	// 扫描状态 ---
	para.FileNo = dhl_fileNo;
	para.FilePos = dhl_filePos;
	para.FileCount = dhl_fileCount;
	para.RequestNo = dhl_logRequestNo;
	para.FileIndexStar = dhl_fileIndexStar;
	para.ShowPageRecords = dhl_showPageRecords;
	para.action = "get_history";

	para.ex_flogin_user = $.cookie("flogin_user");
	para.ex_flogin_md5 = $.cookie("flogin_md5");
	para.ex_flogin_type = $.cookie("flogin_type");
	para.ex_flogin_uid = $.cookie("flogin_uid");
	para.ex_flogin_index = $.cookie("flogin_index");
	var requrl = 'http://'+dhl_app_module_list.applist[appIdx].log_server_ip+':';
	requrl += dhl_app_module_list.applist[appIdx].log_server_port;
	requrl += "<?cs var:config.cgipath?>mt_slog?";
	
	$.ajax({
		url: requrl,
		data: para,
		success: dhlShowHistoryLogResult,
		dataType: 'json', 
		global: false,
		timeout: function(){
			dhl_logRequestNo++;
		},
	});
	return true;
}

function dhlClearLogKey(container, ct2)
{
	var ctstr = "#" + container;
	$(ctstr).html('');

	var ct2str = "#" + ct2;
	$(ct2str).val('');
}

function dhlAddLogKey(isKeyInc, container)
{
	var keyw = "";
	if(isKeyInc)
		keyw = $.trim($("#dhl_key_include").val());
	else
		keyw = $.trim($("#dhl_key_exce").val());
	var ctstr = "#" + container;
	var ct = $(ctstr);
	ct.children('.log-keyword').children('span').each(function () {
		if($(this).text() == keyw) {
			keyw="";
			return false;
		}
	});
	if(keyw == "")
		return;
	var span = $('<span class="log-keyword"><span></span><a href="#" class="close"></a></span>');	
	span.children('span').text(keyw);
	ct.append(span);
	$('#dhl_key_include').val('');
}

function dhlSetLogFileList(result)
{
	if(dmtFirstDealAjaxResponse(result))
		return;

	var logfile = $('#dhlLogFile');
	logfile.html('');
	logfile.append(op);
	var op = $('<option value="0" selected>--- 请选择 ---</option>');
	logfile.append(op);
	var logFind = 0;
	if(result == null || result == 'null' || typeof result.length == "undefined")
		return;

	for(var i=0; i < result.length; i++){
		op = $('<option></option>');
		op.text(result[i]);
		if(dhl_query_log_file == result[i])
		{
			op.attr('selected', true);
			logFind =1;
		}
		logfile.append(op);
	}
	if(logFind == 1) 
	{
		$('#dhlCustLog').css('display', 'block');
		$('#dhlCustTime').css('display', 'none');
		$('#dhlCommTime').css('display', 'none');
		$('#dhl_button_search').click();
	}
}

function dhlOpAppChange()
{
	var idx = $('#dhl_appName').val();
	var app = dhl_app_module_list.applist[idx];
	$('#dhl_flt_app_module').html('');
	$("#dhl_flt_all_am").prop("checked", true);
	for(var i=0; i < app.module_count; i++) {
		var spid = "dhl_flt_module_" + i;
		var sp = $('<div style="margin-left:5px"><input name="dhl_flt_module" type="checkbox" checked /><label class="for"></label></div>');
		sp.children('input').attr('id', spid).attr('title', app.modulelist[i].name).val(app.modulelist[i].id);
		sp.children('label').attr('for', spid).text(app.modulelist[i].name);
		$('#dhl_flt_app_module').append(sp);
	}

	var para = new Object();

	// 应用模块 --
	var appIdx = $("#dhl_appName").val();
	para.appId = dhl_app_module_list.applist[appIdx].app_id;
	if(dhl_app_module_list.applist[appIdx].module_count <= 0){
		return false;
	}
	para.action = "get_app_file_list";
	
	para.ex_flogin_user = $.cookie("flogin_user");
	para.ex_flogin_md5 = $.cookie("flogin_md5");
	para.ex_flogin_type = $.cookie("flogin_type");
	para.ex_flogin_uid = $.cookie("flogin_uid");
	para.ex_flogin_index = $.cookie("flogin_index");
	var requrl = 'http://'+dhl_app_module_list.applist[appIdx].log_server_ip+':';
	requrl += dhl_app_module_list.applist[appIdx].log_server_port;
	requrl += "<?cs var:config.cgipath?>mt_slog?";
	
	$.ajax({
		url: requrl,
		data: para,
		success: dhlSetLogFileList,
		dataType: 'json', 
		global: false,
	});
}

function dhlSetReportMachines()
{
	var op_machine = $('#dhlReportHost');
	if(dhl_report_machines.mach_count <= 0) {
		alertMsg.info("上报机器数目为0，请先添加上报机器");
		return ;
	}
	op_machine.html('');
	var op = $('<option value="0">全部机器</option>');
	op_machine.append(op);

	var mach_list = dhl_report_machines.mach_list;
	for (var i = 0; i < mach_list.length; ++i) { 
		var op = $('<option></option>');
		op.val(mach_list[i].id).text(mach_list[i].name);
		op_machine.append(op);
	}
}

function dhlChangeSortByTime()
{
	if(dhl_result_list_sort_up)
		dhl_result_list_sort_up = false;
	else
		dhl_result_list_sort_up = true;
	dhlSortShowHistoryLog();
}

$(document).ready(function(){
	var op_app = $('#dhl_appName');
	if(dhl_app_module_list.app_count <= 0) {
		alertMsg.warn("应用数目为0，请先添加应用！");
		return ;
	}
	op_app.html('');
	op_app.change(dhlOpAppChange);
	var app_list = dhl_app_module_list.applist;
	var app_sel = window.localStorage.getItem('dhl_app_sel');
	for (var i = 0; i < app_list.length; ++i) { 
		var op = $('<option></option>');
		op.val(i).text(app_list[i].app_name);
		if(dhl_query_app_id != 0) {
			if(app_list[i].app_id == dhl_query_app_id)
				op.attr("selected", true);
		}
		else if((app_sel == null && i==0) || app_sel == app_list[i].app_id)
			op.attr("selected", true);
		op_app.append(op);
	}
	dhlOpAppChange();

	// 上报机器初始化
	dhlSetReportMachines();

	$("#dhl_inc_keylist").delegate('.close', 'click', function(){
			$("#dhl_inc_keylist")[0].removeChild(this.parentNode);
	});

	$("#dhl_exce_keylist").delegate('.close', 'click', function(){
			$("#dhl_exce_keylist")[0].removeChild(this.parentNode);
	});

	dhl_log_type_bg['1'] = 'other';
	dhl_log_type_bg['2'] = 'debug';
	dhl_log_type_bg['4'] = 'info';
	dhl_log_type_bg['8'] = 'warn';
	dhl_log_type_bg['16'] = 'in_error';
	dhl_log_type_bg['32'] = 'error';
	dhl_log_type_bg['64'] = 'fatal';

	// 重要日志&流水日志
	dhl_log_type_nm['1'] = '其它类型';

	dhl_log_type_nm['2'] = '调试日志';
	dhl_log_type_nm['4'] = '信息日志';
	dhl_log_type_nm['8'] = '警告日志';
	dhl_log_type_nm['16'] = '输入错误';
	dhl_log_type_nm['32'] = '程序错误';
	dhl_log_type_nm['64'] = '严重错误';
});

</script>


